#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
检查Excel文件的工作表名称
"""

import pandas as pd

def check_worksheets():
    """检查Excel文件的工作表名称"""
    excel_file = 'tests/data/example_test_cases.xlsx'
    
    try:
        xl = pd.ExcelFile(excel_file)
        print(f"Excel文件: {excel_file}")
        print(f"工作表数量: {len(xl.sheet_names)}")
        print("\n工作表名称:")
        for i, name in enumerate(xl.sheet_names):
            print(f"{i+1}. '{name}'")
            
        # 尝试读取每个工作表的数据
        print("\n工作表数据预览:")
        for sheet_name in xl.sheet_names:
            try:
                df = pd.read_excel(excel_file, sheet_name=sheet_name)
                print(f"\n工作表 '{sheet_name}':")
                print(f"  - 行数: {len(df)}")
                print(f"  - 列数: {len(df.columns)}")
                print(f"  - 列名: {list(df.columns)}")
                if len(df) > 0:
                    print(f"  - 前3行数据:")
                    for i, row in df.head(3).iterrows():
                        print(f"    {i+1}: {row.get('test_case_id', 'N/A')} - {row.get('test_name', 'N/A')}")
            except Exception as e:
                print(f"  读取工作表 '{sheet_name}' 失败: {e}")
                
    except Exception as e:
        print(f"打开Excel文件失败: {e}")

if __name__ == "__main__":
    check_worksheets()